﻿// Copyright 2007, 2008 - Ariel Yaroshevich (a.k.a blackrussian) (hamlet@inter.net.il)
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using SharpMap.Rendering.Rendering2D;
using System.Windows;

namespace SharpMap.Presentation.Wpf.Converters
{
    class TransformToScaleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            SharpMap.Rendering.Rendering2D.Matrix2D sourceMatrix = value as SharpMap.Rendering.Rendering2D.Matrix2D;
            if (targetType == typeof(double) && sourceMatrix != null)
            {
                double scaleX = Math.Abs(1.0 / sourceMatrix.M11);
                double scaleY = Math.Abs(1.0 / sourceMatrix.M22);
                double totalScale = Math.Sqrt((scaleX * scaleX + scaleY * scaleY) / 2.0);
                return totalScale;
 
            }
            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

    }
}
